package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.page.PageUtil;
import com.ruoyi.common.core.page.ResultEntity;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.domain.dto.SysDictDataDTO;
import com.ruoyi.system.service.ISysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/client/dict/data")
@Api(tags = "(客户端) 数据字典明细")
public class TDictDataController {
    @Resource
    private ISysDictDataService dictDataService;

    @GetMapping("/list")
    @ApiOperation(value = "字典值列表查询", response = SysDictData.class)
    public ResultEntity list(SysDictDataDTO params) {
        PageUtil.startPage(params);
        return ResultEntity.createSuccess(PageUtil.getPageList(dictDataService.getDictDataList(params)));
    }

    @ApiOperation(value = "查询字典数据列表")
    @GetMapping("/getDictDataByDictCode/{dictCode}")
    public ResultEntity<List<SysDictData>> getDictDataByCode(@ApiParam(value = "字典code", required = true) @PathVariable String dictCode) {
        List<SysDictData> list = dictDataService.list(Wrappers.<SysDictData>lambdaQuery().eq(SysDictData::getDictType, dictCode));
        return ResultEntity.createSuccess(list);
    }
}
